package com.chart.web.controller.chart;

import com.chart.common.utils.FileUtil;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 文件导出
 *
 * @author 罗继全
 * 2024/7/1 13:19
 */
@RestController
@RequestMapping("/files")
public class FileExportController {

    /**
     * 导出excel
     *
     * @param response
     * @param dataList
     */
    @PostMapping("/excel")
    public void exportUser(HttpServletResponse response, @RequestBody List<Map<String, Object>> dataList) {
        try {
            FileUtil excel = new FileUtil();
            excel.exportExcelWithoutFirstRow(response, dataList, "用户数据");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 导出cvs文件
     *
     * @param response
     * @param dataList
     */
    @PostMapping("/csv")
    public void exportUserCsv(HttpServletResponse response, @RequestBody List<Map<String, Object>> dataList) {
        try {
            FileUtil fileUtilA = new FileUtil();
            fileUtilA.exportCsvWithoutHeader(response, dataList, "用户数据");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
